package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import types.ConsoleType;
import controller.Console;
import controller.PanelSwitcher;
import controller.Refresh;
import view.PanelDASboard;

@SuppressWarnings("serial")
public class PanelSelector extends JPanel {

	private static PanelSelector single;

	private JButton Dashboard = new JButton("DASboard");
	private JButton Klassen = new JButton("Klassen");
	private JButton docenten = new JButton("Docenten");
	private JButton users = new JButton("Gebruikers");

	private JButton refresh = new JButton("Vernieuwen");
	private JButton ShutDown = new JButton("Afsluiten");
	private JButton ShutDown2 = new JButton("klik nogmaals");
	private JButton Export	= new JButton("Export");

	

	private PanelSelector() {

		setLayout(null);
		setBounds(0, 0, 1000, 30);
		setBackground(null);

		Dashboard.setBackground(Color.LIGHT_GRAY);
		docenten.setBackground(Color.DARK_GRAY);
		Export.setBackground(Color.DARK_GRAY);
		users.setBackground(Color.DARK_GRAY);
		Klassen.setBackground(Color.DARK_GRAY);
		ShutDown.setBackground(Color.DARK_GRAY);
		ShutDown2.setVisible(false);
		ShutDown.setVisible(true);

		Dashboard.setSize(140, 30);
		Dashboard.setLocation(0, 0);
		Dashboard.setActionCommand("DASboard");
		Dashboard.addActionListener(new PanelSwitcher());

//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/home2.png/"));
//			Dashboard.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error home2");
//		}
		Dashboard.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				Dashboard.setBackground(Color.LIGHT_GRAY);
				Export.setBackground(Color.DARK_GRAY);
				Klassen.setBackground(Color.DARK_GRAY);
				docenten.setBackground(Color.DARK_GRAY);
				users.setBackground(Color.DARK_GRAY);
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);

			}
		});
		
		Dashboard.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				PanelDASboard.getInstance().resetDeleteButtons();
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		});

		Klassen.setSize(140, 30);
		Klassen.setLocation(282, 0);
		Klassen.setActionCommand("klas");
		Klassen.addActionListener(new PanelSwitcher());
		//Klassen.setBackground(Color.WHITE);
//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/group.png/"));
//			Klassen.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error group");
//		}
		Klassen.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				Klassen.setBackground(Color.LIGHT_GRAY);
				Export.setBackground(Color.DARK_GRAY);
				Dashboard.setBackground(Color.DARK_GRAY);
				docenten.setBackground(Color.DARK_GRAY);
				users.setBackground(Color.DARK_GRAY);
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);

			}

		});

		docenten.setSize(140, 30);
		docenten.setLocation(141, 0);
		docenten.setActionCommand("docent");
		docenten.addActionListener(new PanelSwitcher());

//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/teacher.png/"));
//			docenten.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error teacher");
//		}
		docenten.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				docenten.setBackground(Color.LIGHT_GRAY);
				Export.setBackground(Color.DARK_GRAY);
				Dashboard.setBackground(Color.DARK_GRAY);
				Klassen.setBackground(Color.DARK_GRAY);
				users.setBackground(Color.DARK_GRAY);
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);

			}
		});
		Export.setSize(70, 30);
		Export.setLocation(803, 0);
		Export.setActionCommand("Export");
		Export.addActionListener(new PanelSwitcher());

//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/teacher.png/"));
//			docenten.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error teacher");
//		}
		Export.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				Export.setBackground(Color.LIGHT_GRAY);
				docenten.setBackground(Color.DARK_GRAY);
				Dashboard.setBackground(Color.DARK_GRAY);
				Klassen.setBackground(Color.DARK_GRAY);
				users.setBackground(Color.DARK_GRAY);
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);

			}
		});

		users.setSize(140, 30);
		users.setLocation(423, 0);
		users.setActionCommand("gebruiker");
		users.addActionListener(new PanelSwitcher());

//		try {
//			Image img = ImageIO.read(getClass()
//					.getResource("/Images/User.png/"));
//			users.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error User");
//		}
		users.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				users.setBackground(Color.LIGHT_GRAY);
				Export.setBackground(Color.DARK_GRAY);
				Dashboard.setBackground(Color.DARK_GRAY);
				Klassen.setBackground(Color.DARK_GRAY);
				docenten.setBackground(Color.DARK_GRAY);
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);

			}
		});

		refresh.setSize(140, 30);
		refresh.setLocation(563, 0);
		refresh.setActionCommand("refresh");
		refresh.addActionListener(new Refresh());
		refresh.setBackground(Color.GREEN);
//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/Refresh.png/"));
//			refresh.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//			System.err.println("image error refresh");
//		}
		refresh.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				ShutDown2.setVisible(false);
				ShutDown.setVisible(true);				
				String message = null;
				ConsoleType type = null;
				message = "Alle inhoud word vernieuwd, een ogenblik geduld AUB..";
				type = ConsoleType.REFRESH;
				Console.getInstance().setConsole(message, type);

			}

		});

		ShutDown2.setSize(100, 30);
		ShutDown2.setLocation(703, 0);
		ShutDown2.setActionCommand("klik nogmaals");
		ShutDown2.setBackground(Color.RED);
//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/shutdown.png/"));
//			ShutDown2.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//		System.err.println("image error shutdown2");		
		
//		}
		ShutDown2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				Main_Frame mf = Main_Frame.getInstance();
				mf.dispose();
			}
		});

		ShutDown.setSize(100, 30);
		ShutDown.setLocation(703, 0);
		ShutDown.setActionCommand("Afsluiten");
		ShutDown.setBackground(Color.WHITE);
//		try {
//			Image img = ImageIO.read(getClass().getResource(
//					"/Images/shutdown.png/"));
//			ShutDown.setIcon(new ImageIcon(img));
//		} catch (IOException ex) {
//		System.err.println("image error shutdown");
//		}
		ShutDown.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent mouseEvent) {
				ShutDown.setVisible(false);
				add(ShutDown2);
				ShutDown2.setVisible(true);

			}

		});
		add(Export);
		add(Dashboard);
		add(Klassen);
		add(docenten);
		add(users);
		add(refresh);
		add(ShutDown);

	}

	public static PanelSelector getInstance() {
		if (single == null) {
			single = new PanelSelector();
		}
		return single;
	}

	public static void selfDestory() {
		single = null;
	}

	public JButton getKlassen() {
		return Klassen;
	}

	public void setKlassen(JButton klassen) {
		Klassen = klassen;
	}

	public JButton getDocenten() {
		return docenten;
	}

	public void setDocenten(JButton docenten) {
		this.docenten = docenten;
	}

	public JButton getDashboard() {
		return docenten;
	}

	public void setDashboard(JButton docenten) {
		this.docenten = docenten;
	}

	public JButton getShutDown() {
		return ShutDown;
	}

	public void setShutDown(JButton ShutDown) {
		this.ShutDown = ShutDown;
	}

	public JButton getRefresh() {
		return refresh;
	}

	public void setRefresh(JButton refresh) {
		this.refresh = refresh;
	}

	public static JLabel addTitle(String title) {
		Font myFont = new Font("Arial", Font.BOLD, 20);
		JLabel header = new JLabel(title);
		header.setBounds(100, 30, 300, 30);
		header.setFont(myFont);
		return header;

	}
}
